package com.demo.search.io;

import java.io.File;

/**
 * 文件扩展名过滤器
 * @author ryuu.kk
 *
 */
public class ExtensionFileFilter implements java.io.FileFilter {

	private String[] extensions = {};
	@Override
	public boolean accept(File pathname) {
		
		// 非文件夹&文件存在
		if (!pathname.isDirectory() && pathname.exists()) {
			boolean isAccept = false;
			for (String ext : extensions) {
				if (pathname.getPath().endsWith(ext)) {
					isAccept = true;
				}
				if (isAccept) {
					return true;
				}
			}
		}

		return false;
	}

	public void setExtensions(String[] args) {
		extensions = args;
	}
}
